#include <iostream>
#include <queue>
#include <string.h>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
const int inf=0x7fffffff;


struct edge{
	int stop,len;
	bool operator < (const edge a)const{
		return len>a.len;
	}
};
vector<edge> e[10000];



int dis(int n,int mid,int city[]){
	if(city[0] > mid)
		return -1;
	int dis[n];
	memset(dis,-1,sizeof(dis));
	dis[0] = 0;
	priority_queue<edge> q;
	for(int i=0;i<e[0].size();i++){
		if(city[e[0][i].stop] <= mid)
			q.push(e[0][i]);
	}
	for(int i=1;i<n;i++){
		if(dis[n-1] != -1)
			break;
		while(!q.empty()  &&  dis[q.top().stop] != -1){
			q.pop();
		}
		if(q.empty()  &&  dis[n-1] == -1)
			return -1;
		edge l;
		l = q.top();
		q.pop();
		dis[l.stop] = l.len;
		
		for(int i=0;i<e[l.stop].size();i++){
			if(city[e[l.stop][i].stop] <= mid  &&  dis[e[l.stop][i].stop] == -1)
				q.push({e[l.stop][i].stop,dis[l.stop]+e[l.stop][i].len});
		}
	}
	return dis[n-1];
}



signed main(){
	int n,m,b;
	cin>>n>>m>>b;
	int city[n];
	int l=inf,r=inf+1;
	for(int i=0;i<n;i++){
		cin>>city[i];
		l = min(l,city[i]);
		r = max(r,city[i]);
	}
	for(int i=0;i<m;i++){
		int s,t,l;
		cin>>s>>t>>l;
		s--;
		t--;
		e[s].push_back({t,l});
		e[t].push_back({s,l});
	}
	
	
	while(l < r-1){
		int mid=(l+r)/2;
//		cout<<mid<<endl;
		int d=dis(n,mid,city);
		if(d <= b  &&  d != -1)
			r = mid;
		else
			l = mid;
	}
	int d=dis(n,l,city);
	if(d <= b  &&  d != -1)
		cout<<l;
	else{
		d = dis(n,r,city);
		if(d <= b  &&  d != -1)
			cout<<r;
		else
			cout<<"AFK";
	}
	return 0;
}
